package sample.components
{
	import asf.utils.FX;
	
	import br.pedromoraes.btween.ISequenceable;
	
	import flash.display.Shape;
	import flash.display.Sprite;

	public class Preloader extends Sprite
	{
		private const W:uint = 100;
		private const H:uint = 10;
		
		private var bar:Shape;
		
		public function Preloader( )
		{
			super( );
			
			bar = new Shape( );
			
			bar.graphics.beginFill( 0, 1 );
			graphics.beginFill( 0xFFFFFF, 1 );
			
			graphics.lineStyle( 0, 0, 1 );
			
			graphics.drawRect( 0, 0, W, H );
			bar.graphics.drawRect( 0, 0, W, H );
			
			addChild( bar );
			setProgress( 0 );
			
			alpha = 0;
			visible = false;
		}
		
		public function setProgress( value:Number ):void
		{
			bar.scaleX = Math.max( 0, Math.min( 1, value ) );
		}
		
		public function show( ):ISequenceable
		{
			return FX.fadeIn( this );
		}
		
		public function hide( ):ISequenceable
		{
			return FX.fadeOut( this );
		}
	}
}